﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DiskInspector.Model
{
    public static class DataExtensions
    {
        public static string ToByteString(this byte[] data)
        {
            var stringBuilder = new StringBuilder();

            foreach (var hex in data)
            {
                stringBuilder.Append(hex.ToString("X2"));
                stringBuilder.Append(@" ");
            }

            return stringBuilder.ToString();
        }

        public static string ToByteFlatString(this byte[] data)
        {
            char[] lookup = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
            int i = 0, j = 0, l = data.Length;
            char[] c = new char[l * 2];

            while (i < l)
            {
                byte d = data[i++];
                c[j++] = lookup[d >> 4];
                c[j++] = lookup[d & 0xF];
            }

            return new string(c, 0, c.Length);
        }

        public static string ToByteString(this byte data)
        {
            return data.ToString("X2");
        }
    }
}
